package empox.pos.system.print;

import android.content.Context;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

public class PrintInfoAdapter extends BaseAdapter {
	Context con;

	public PrintInfoAdapter(Context con) {
		this.con = con;
	}

	public int getCount() {
		if (PrintDB.tempElementlist == null)
			return 0;
		else
			return PrintDB.tempElementlist.size();
	}

	public Object getItem(int position) {
		return position;
	}

	public long getItemId(int position) {
		return position;
	}

	static class SH {
		TextView tv1;
		TextView tv2;
		TextView tv3;
		TextView tv4;
		TextView tv5;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		SH sh = new SH();

		if (convertView == null) {
			convertView = new LinearLayout(con);
			((LinearLayout) convertView).setGravity(Gravity.CENTER);

			sh.tv1 = new TextView(con);
			sh.tv1.setWidth(100);
			sh.tv1.setHeight(30);
			sh.tv1.setGravity(Gravity.CENTER);
			sh.tv1.setTextColor(0xff57290a);
			((LinearLayout) convertView).addView(sh.tv1);

			sh.tv2 = new TextView(con);
			sh.tv2.setWidth(100);
			sh.tv2.setHeight(30);
			sh.tv2.setGravity(Gravity.CENTER);
			sh.tv2.setTextColor(0xff57290a);
			((LinearLayout) convertView).addView(sh.tv2);

			sh.tv3 = new TextView(con);
			sh.tv3.setWidth(100);
			sh.tv3.setHeight(30);
			sh.tv3.setGravity(Gravity.CENTER);
			sh.tv3.setTextColor(0xff57290a);
			((LinearLayout) convertView).addView(sh.tv3);

			sh.tv4 = new TextView(con);
			sh.tv4.setWidth(100);
			sh.tv4.setHeight(30);
			sh.tv4.setGravity(Gravity.CENTER);
			sh.tv4.setTextColor(0xff57290a);
			((LinearLayout) convertView).addView(sh.tv4);

			sh.tv5 = new TextView(con);
			sh.tv5.setWidth(400);
			sh.tv5.setHeight(30);
			sh.tv5.setGravity(Gravity.CENTER);
			sh.tv5.setTextColor(0xff57290a);
			((LinearLayout) convertView).addView(sh.tv5);

			convertView.setTag(sh);
		} else {
			sh = (SH) convertView.getTag();
		}

		PrintElement pe = PrintDB.tempElementlist.get(position);
		
		Log.v("text", "tx1:"+PrintDB.tempcustomlist.get(position).dispName);
		sh.tv1.setText(PrintDB.tempcustomlist.get(position).dispName);
		
		sh.tv2.setText(String.valueOf(pe.align));
		sh.tv3.setText(String.valueOf(pe.width));
		sh.tv4.setText(String.valueOf(pe.appendBR));
		sh.tv5.setText(pe.content);

		return convertView;
	}

}
